import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;

import java.sql.SQLException;

public class Main {
    public static void main(String[] args) {

        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mysql://localhost:3306/jdbc");
        dataSource.setUsername("root");
        dataSource.setPassword("111111");
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setInitialSize(5); //初始化连接池大小
        dataSource.setMaxActive(10);//最大连接池大小
         dataSource.setMinIdle(5);//最小连接池大小
         dataSource.setMaxWait(5000);   //获取连接的最大等待时间
         dataSource.setValidationQuery("select 1");// 验证连接是否有效
       try {
         DruidPooledConnection connection = dataSource.getConnection();
        if(connection != null){
            System.out.println("连接成功");
        }
       }
       catch (SQLException e){
           throw  new RuntimeException(e);
       }
    }
}